package com.auxgroup.smarthome.controller;


import com.auxgroup.smarthome.basebean.MenuTypeEnum;
import com.auxgroup.smarthome.dto.MenuDto;
import com.auxgroup.smarthome.filter.annotation.PermissionMenu;
import com.auxgroup.smarthome.service.MenuService;
import com.auxgroup.smarthome.session.SessionMenu;
import com.auxgroup.smarthome.web.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;



@Api(tags = "菜单管理", hidden = false)
@RestController
@RequestMapping(value = "/upms/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @ApiIgnore
    @ApiOperation(value = "创建功能菜单")
    @PostMapping( value = "/create")
    @PermissionMenu(id = "upms_menu_create", parentId = "umps_menu_menu_manage", name = "创建菜单", menuType = MenuTypeEnum.BUTTON)
    public ApiResponse create(@RequestBody MenuDto menuDto) {
        return menuService.createMenu(menuDto);
    }

    @ApiIgnore
    @ApiOperation(value = "删除功能菜单")
    @RequestMapping( value = "/delete/{id}", method = RequestMethod.DELETE)
    @PermissionMenu(id = "upms_menu_delete", parentId = "umps_menu_menu_manage", name = "删除菜单", menuType = MenuTypeEnum.BUTTON)
    public ApiResponse delete(@PathVariable("id") String id) {
        return menuService.deleteMenuById(id);
    }

    @ApiIgnore
    @ApiOperation(value = "更新功能菜单")
    @PutMapping( value = "/update")
    @PermissionMenu(id = "upms_menu_update", parentId = "umps_menu_menu_manage", name = "更新菜单", menuType = MenuTypeEnum.BUTTON)
    public ApiResponse update(@RequestBody MenuDto menuDto) {
        return menuService.updateMenu(menuDto);
    }


    @ApiOperation(value = "展示所有功能菜单（不分页）")
    @GetMapping(value = "/list")
    @PermissionMenu(id = "upms_menu_list", parentId = "umps_menu_menu_manage", name = "菜单列表", menuType = MenuTypeEnum.BUTTON)
    public ApiResponse<List<SessionMenu>> getMenuList() {
        List<SessionMenu> allMenus = menuService.getShowAllMenus();
        return ApiResponse.ok(allMenus);
    }


}
